package com.mytest.lock;

public class Lock2 implements Runnable {
    @Override
    public void run() {

        try{
            System.out.println("Lock2 running");
            while(true){
                synchronized(DeadLock.obj2){
                      System.out.println("Lock2 lock obj2");
                      Thread.sleep(3000);  //获取obj2后先等一会儿，让Lock1有足够的时间锁住obj1
                      synchronized(DeadLock.obj1){
                            System.out.println("Lock2 lock obj1");
                      }
                }
            }
        }catch(Exception e){
              e.printStackTrace();
        }

    }
}
